"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CommandLoader = void 0;
const chalk_1 = require("chalk");
const actions_1 = require("../actions");
const ui_1 = require("../lib/ui");
const build_command_1 = require("./build.command");
const code_scan_command_1 = require("./code-scan.command");
const generate_command_1 = require("./generate.command");
const info_command_1 = require("./info.command");
const help_command_1 = require("./help.command");
const new_command_1 = require("./new.command");
const start_command_1 = require("./start.command");
const test_command_1 = require("./test.command");
const transpile_command_1 = require("./transpile.command");
const update_command_1 = require("./update.command");
const pluginsify_1 = require("./pluginsify");
class CommandLoader {
    static load(program) {
        // program.option('--registry [registry]', 'npm 地址默认值 http://nexus.coraise.cn/content/groups/cpaas-npm-group/')
        new new_command_1.NewCommand(new actions_1.NewAction()).load(program);
        new build_command_1.BuildCommand(new actions_1.BuildAction()).load(program);
        new start_command_1.StartCommand(new actions_1.StartAction()).load(program);
        new generate_command_1.GenerateCommand(new actions_1.GenerateAction()).load(program);
        new info_command_1.InfoCommand(new actions_1.InfoAction()).load(program);
        new update_command_1.UpdateCommand(new actions_1.UpdateAction()).load(program);
        new transpile_command_1.TranspileCommand(new actions_1.TranspileAction()).load(program);
        new test_command_1.TestCommand(new actions_1.TestAction()).load(program);
        new code_scan_command_1.CodeScanCommand(new actions_1.CodeScanAction()).load(program);
        new help_command_1.HelpCommand().load(program);
        try {
            new pluginsify_1.Pluginsify().load(program);
        }
        catch (e) {
            console.error(e);
        }
        this.handleInvalidCommand(program);
    }
    static handleInvalidCommand(program) {
        program.on('command:*', () => {
            console.error(`\n${ui_1.ERROR_PREFIX} Invalid command: ${chalk_1.default.red('%s')}`, program.args.join(' '));
            console.log(`See ${chalk_1.default.red('--help')} for a list of available commands.\n`);
            process.exit(1);
        });
    }
}
exports.CommandLoader = CommandLoader;
